﻿using System;
using System.Globalization;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace WorkGps
{
    public class RMCGPSParcer:IGPSParcer
    {

        public GPSData Parce(string[] data)
        {
            
            foreach (string elem in data)
            {
                elem.Replace(".", CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator);
            }
            GPSData gpsData = new GPSData();
            gpsData.time = new DateTime(
                1, 1, 1,
                Convert.ToInt32(data[1].Substring(0, 2)),
                Convert.ToInt32(data[1].Substring(2, 2)),
                Convert.ToInt32(data[1].Substring(4, 2)),
                Convert.ToInt32(data[1].Substring(7, 1))*100);

            gpsData.lat = Convert.ToInt32(data[3].Substring(0, 2)) +
                Convert.ToDouble(data[3].Substring(2)) / 60;

            if (data[4] == "S")
                gpsData.lat = -gpsData.lat;

            gpsData.lon = Convert.ToInt32(data[5].Substring(0, 3)) +
                Convert.ToDouble(data[5].Substring(3)) / 60;
            if (data[6] == "W")
                gpsData.lon = -gpsData.lon;

            gpsData.date = new DateTime(
                Convert.ToInt32(data[9].Substring(4, 2)),
                Convert.ToInt32(data[9].Substring(2, 2)),
                Convert.ToInt32(data[9].Substring(0, 2)));
            return gpsData;
        }
    }
}
